﻿using System;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;

namespace HamcoWcs.DAL.Migrations
{
    public partial class A9 : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "device_error_log_bak");

            migrationBuilder.DropTable(
                name: "device_msg_log_bak");

            migrationBuilder.DropTable(
                name: "msg_info_config");

            migrationBuilder.DropTable(
                name: "wcs_run_log_bak");

            migrationBuilder.DropTable(
                name: "msg_info_group_config");

            migrationBuilder.DropColumn(
                name: "OccurTime",
                table: "device_error_log");

            migrationBuilder.DropColumn(
                name: "OccurTime",
                table: "device_error_info");

            migrationBuilder.AlterColumn<string>(
                name: "UnitId",
                table: "operation_log",
                type: "varchar(50)",
                maxLength: 50,
                nullable: true,
                comment: "条码号",
                oldClrType: typeof(string),
                oldType: "varchar(30)",
                oldMaxLength: 30,
                oldComment: "条码号")
                .Annotation("MySql:CharSet", "utf8mb4")
                .OldAnnotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.AlterColumn<string>(
                name: "Remark",
                table: "operation_log",
                type: "text",
                maxLength: 100,
                nullable: false,
                comment: "具体操作",
                oldClrType: typeof(string),
                oldType: "varchar(4096)",
                oldMaxLength: 4096,
                oldComment: "具体操作")
                .Annotation("MySql:CharSet", "utf8mb4")
                .OldAnnotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.AddColumn<string>(
                name: "Controller",
                table: "operation_log",
                type: "varchar(30)",
                maxLength: 30,
                nullable: false,
                defaultValue: "",
                comment: "控制器")
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.AddColumn<string>(
                name: "MethodName",
                table: "operation_log",
                type: "varchar(30)",
                maxLength: 30,
                nullable: false,
                defaultValue: "",
                comment: "方法")
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.AddColumn<DateTime>(
                name: "CreatedTime",
                table: "device_error_log",
                type: "datetime(6)",
                nullable: false,
                defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified));

            migrationBuilder.AddColumn<DateTime>(
                name: "LastUpdateTime",
                table: "device_error_log",
                type: "datetime(6)",
                nullable: false,
                defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified));

            migrationBuilder.AddColumn<DateTime>(
                name: "CreatedTime",
                table: "device_error_info",
                type: "datetime(6)",
                nullable: false,
                defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified));

            migrationBuilder.AddColumn<DateTime>(
                name: "LastUpdateTime",
                table: "device_error_info",
                type: "datetime(6)",
                nullable: false,
                defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified));
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropColumn(
                name: "Controller",
                table: "operation_log");

            migrationBuilder.DropColumn(
                name: "MethodName",
                table: "operation_log");

            migrationBuilder.DropColumn(
                name: "CreatedTime",
                table: "device_error_log");

            migrationBuilder.DropColumn(
                name: "LastUpdateTime",
                table: "device_error_log");

            migrationBuilder.DropColumn(
                name: "CreatedTime",
                table: "device_error_info");

            migrationBuilder.DropColumn(
                name: "LastUpdateTime",
                table: "device_error_info");

            migrationBuilder.AlterColumn<string>(
                name: "UnitId",
                table: "operation_log",
                type: "varchar(30)",
                maxLength: 30,
                nullable: false,
                defaultValue: "",
                comment: "条码号",
                oldClrType: typeof(string),
                oldType: "varchar(50)",
                oldMaxLength: 50,
                oldNullable: true,
                oldComment: "条码号")
                .Annotation("MySql:CharSet", "utf8mb4")
                .OldAnnotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.AlterColumn<string>(
                name: "Remark",
                table: "operation_log",
                type: "varchar(4096)",
                maxLength: 4096,
                nullable: false,
                comment: "具体操作",
                oldClrType: typeof(string),
                oldType: "text",
                oldMaxLength: 100,
                oldComment: "具体操作")
                .Annotation("MySql:CharSet", "utf8mb4")
                .OldAnnotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.AddColumn<DateTime>(
                name: "OccurTime",
                table: "device_error_log",
                type: "datetime(6)",
                nullable: false,
                defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
                comment: "发生时间");

            migrationBuilder.AddColumn<DateTime>(
                name: "OccurTime",
                table: "device_error_info",
                type: "datetime(6)",
                nullable: false,
                defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
                comment: "发生时间");

            migrationBuilder.CreateTable(
                name: "device_error_log_bak",
                columns: table => new
                {
                    Id = table.Column<long>(type: "bigint", nullable: false, comment: "主键Id")
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    DeviceName = table.Column<string>(type: "varchar(30)", maxLength: 30, nullable: false, comment: "设备名")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    ErrorCode = table.Column<string>(type: "varchar(30)", maxLength: 30, nullable: false, comment: "异常代码")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    ErrorDetail = table.Column<string>(type: "varchar(255)", maxLength: 255, nullable: false, comment: "异常说明")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    OccurTime = table.Column<DateTime>(type: "datetime(6)", nullable: false, comment: "发生时间"),
                    PlcName = table.Column<string>(type: "varchar(30)", maxLength: 30, nullable: false, comment: "PLC名")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    SetTime = table.Column<DateTime>(type: "datetime(6)", nullable: false, comment: "恢复时间")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_device_error_log_bak", x => x.Id);
                },
                comment: "设备异常日志备份表")
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "device_msg_log_bak",
                columns: table => new
                {
                    Id = table.Column<long>(type: "bigint", nullable: false, comment: "主键Id")
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    CreatedTime = table.Column<DateTime>(type: "datetime(6)", nullable: false),
                    DeviceName = table.Column<string>(type: "varchar(30)", maxLength: 30, nullable: true, comment: "设备名")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    LastUpdateTime = table.Column<DateTime>(type: "datetime(6)", nullable: false),
                    MsgValue = table.Column<string>(type: "varchar(500)", maxLength: 500, nullable: false, comment: "创建时间")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    PlcName = table.Column<string>(type: "varchar(30)", maxLength: 30, nullable: false, comment: "PLC名")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    TaskId = table.Column<string>(type: "varchar(30)", maxLength: 30, nullable: true, comment: "任务号")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    UnitId = table.Column<string>(type: "varchar(30)", maxLength: 30, nullable: true, comment: "托盘号")
                        .Annotation("MySql:CharSet", "utf8mb4")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_device_msg_log_bak", x => x.Id);
                },
                comment: "设备消息日志备份表")
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "msg_info_group_config",
                columns: table => new
                {
                    Id = table.Column<long>(type: "bigint", nullable: false, comment: "主键Id")
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    GroupDescription = table.Column<string>(type: "varchar(30)", maxLength: 30, nullable: true, comment: "类型中文名")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    GroupName = table.Column<string>(type: "varchar(30)", maxLength: 30, nullable: true, comment: "类型英文名")
                        .Annotation("MySql:CharSet", "utf8mb4")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_msg_info_group_config", x => x.Id);
                },
                comment: "消息类型中英对照表")
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "wcs_run_log_bak",
                columns: table => new
                {
                    Id = table.Column<long>(type: "bigint", nullable: false, comment: "主键Id")
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    CreatedTime = table.Column<DateTime>(type: "datetime(6)", nullable: false),
                    LastUpdateTime = table.Column<DateTime>(type: "datetime(6)", nullable: false),
                    MsgValue = table.Column<string>(type: "varchar(30)", maxLength: 30, nullable: false, comment: "消息内容")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    UnitId = table.Column<string>(type: "varchar(30)", maxLength: 30, nullable: true, comment: "托盘号")
                        .Annotation("MySql:CharSet", "utf8mb4")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_wcs_run_log_bak", x => x.Id);
                },
                comment: "wcs运行日志备份表")
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "msg_info_config",
                columns: table => new
                {
                    Id = table.Column<long>(type: "bigint", nullable: false, comment: "主键Id")
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    ConfigGroupId = table.Column<long>(type: "bigint", nullable: true),
                    ConfigKey = table.Column<string>(type: "varchar(30)", maxLength: 30, nullable: true, comment: "索引")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    ConfigMsgInfoGroup = table.Column<string>(type: "varchar(100)", maxLength: 100, nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    ConfigValue = table.Column<string>(type: "varchar(30)", maxLength: 30, nullable: true, comment: "值")
                        .Annotation("MySql:CharSet", "utf8mb4")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_msg_info_config", x => x.Id);
                    table.ForeignKey(
                        name: "FK_msg_info_config_msg_info_group_config_ConfigGroupId",
                        column: x => x.ConfigGroupId,
                        principalTable: "msg_info_group_config",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                },
                comment: "消息明细")
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateIndex(
                name: "IX_msg_info_config_ConfigGroupId",
                table: "msg_info_config",
                column: "ConfigGroupId");
        }
    }
}
